<?php
if ( defined('ABSPATH') )
	include_once ABSPATH . 'config.php';
else
    include_once 'config.php';

include_once ABSPATH."base/posts.php";

// how many rows to show per page
$rowsPerPage = 20;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_POST['page']))
{
	$pageNum = $_POST['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;





if(isset($_POST["id"]) && isset($_POST["channel"]) && $_POST["cmd"] == "posts")
{

	$posts = new Post();
	$id = $_POST["id"];
	$channel = $_POST["channel"];
	$rs = $posts->ConnectionsGet($id, $channel, $offset, $rowsPerPage);
	$numRows = $posts->ConnectionsGetTotalCount($id,$channel);
	
	if($rs)
	{
		foreach($rs as $row)
		{
		    echo '<div class="post-row"><table><tr><td><a href="'.$row["address"].'"><div class="profile-image"><img alt="'.$row["name"].'" src="'.$row["image"].'"  /></div></a></td>';
		    echo '<td><strong><a href="'.$row["address"].'" title="'.$row["name"].'">'.$row["screen_name"].'</a></strong> ';
		        //$rss .= makeClickableLinks($text).' ';
		    echo $row["status"].' ';
		    echo '<p><a href="'.$row["link"].'" target="_blank">'.$row["link"].'</a></p>';
		    echo '<p>'.$row["tags"].'</p>';
		    echo '<a href="'.$row["address"].'">'.$row["timestamp"].'</a>';
		    echo ' from '.$row["source"].'</td></tr></table></div> ';
		}
		
		// how many pages we have when using paging?
		$maxPage = ceil($numRows/$rowsPerPage);
		
		
		$self = $_SERVER['PHP_SELF'];
		
		// creating 'previous' and 'next' link
		// plus 'first page' and 'last page' link
		
		// print 'previous' link only if we're not
		// on page one
		if ($pageNum > 1)
		{
			$page = $pageNum - 1;
			$prev = " <a href='javascript:void(0)' onclick='PostRefresh(DOM(\"id\").value,DOM(\"channel\").options[DOM(\"channel\").selectedIndex].value,$page);'>&lt;</a> ";
			$first = " <a href='javascript:void(0)' onclick='PostRefresh(DOM(\"id\").value,DOM(\"channel\").options[DOM(\"channel\").selectedIndex].value,1);'>&lt;&lt;</a> | ";
		} 
		else
		{
			$prev  = ' | &lt; ';       // we're on page one, don't enable 'previous' link
			$first = ' &lt;&lt; '; // nor 'first page' link
		}
		
		// print 'next' link only if we're not
		// on the last page
		if ($pageNum < $maxPage)
		{
			$page = $pageNum + 1;
			$next = " <a href='javascript:void(0)' onclick='PostRefresh(DOM(\"id\").value,DOM(\"channel\").options[DOM(\"channel\").selectedIndex].value,$page);'>&gt;</a> | ";
			$last = " <a href='javascript:void(0)' onclick='PostRefresh(DOM(\"id\").value,DOM(\"channel\").options[DOM(\"channel\").selectedIndex].value,$maxPage);'>&gt;&gt;</a> ";
		} 
		else
		{
			$next = ' &gt; | ';      // we're on the last page, don't enable 'next' link
			$last = ' &gt;&gt; '; // nor 'last page' link
		}
		
		// print the page navigation link
		echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;
			
		
		
		
	}

}
?>
